package org.skatiger.jrove.component.html;

import javax.el.ValueExpression;

import org.skatiger.jrove.JroveContext;
import org.skatiger.jrove.component.UIComponent;
import org.skatiger.jrove.tag.ComponentConfig;
import org.skatiger.jrove.tag.ComponentHandler;

public class NavigationHandler extends ComponentHandler {

    public NavigationHandler(ComponentConfig config) {
        super(config);
    }

    @Override
    protected void onComponentPopulated(JroveContext jroveContext,
            UIComponent c, UIComponent parent) {
        if (Navigation.class.isAssignableFrom(c.getClass())) {
            Navigation navigation = (Navigation) c;
            String activeName = navigation.getActiveItemName();
            ValueExpression ve = jroveContext.getVariableMapper()
                    .resolveVariable(activeName);
            if (ve != null) {
                String active = (String) ve.getValue(jroveContext);
                navigation.setActiveItemId(active);
            }
        }
    }
}
